package com.youyi.yycutsdklibrary.SDK;

import android.content.Intent;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import com.youyi.yycutsdklibrary.CropCore.CropImage;
import com.youyi.yycutsdklibrary.CropCore.CropImageView;
import com.youyi.yycutsdklibrary.SDK.YYCutSDK;
import java.io.File;

public class YYCutSDKActivity extends AppCompatActivity {
    /* access modifiers changed from: protected */
    @Override // android.support.v7.app.AppCompatActivity, android.support.v4.app.SupportActivity, android.support.v4.app.FragmentActivity
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        getWindow().addFlags(16);
        if (bundle == null) {
            resloveIntent(getIntent());
        }
    }

    /* access modifiers changed from: protected */
    @Override // android.support.v4.app.FragmentActivity
    public void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        resloveIntent(getIntent());
    }

    private void resloveIntent(Intent intent) {
        Log.d("CropImageView", "optionsmaxZoom:50");
        String stringExtra = intent.getStringExtra("imgPath");
        boolean booleanExtra = intent.getBooleanExtra("isShowLine", true);
        boolean booleanExtra2 = intent.getBooleanExtra("isOval", false);
        boolean booleanExtra3 = intent.getBooleanExtra("isSquare", false);
        int intExtra = intent.getIntExtra("width", 0);
        int intExtra2 = intent.getIntExtra("height", 0);
        Uri fromFile = Uri.fromFile(new File(stringExtra));
        if (Build.VERSION.SDK_INT >= 24) {
            fromFile = FileProvider.getUriForFile(this, getPackageName() + ".fileprovider", new File(stringExtra));
        }
        CropImage.ActivityBuilder guidelines = CropImage.activity(fromFile).setGuidelines(booleanExtra ? CropImageView.Guidelines.ON : CropImageView.Guidelines.OFF);
        if (booleanExtra2) {
            guidelines.setCropShape(CropImageView.CropShape.OVAL);
            guidelines.setAspectRatio(1, 1);
        } else {
            guidelines.setCropShape(CropImageView.CropShape.RECTANGLE);
            if (booleanExtra3) {
                guidelines.setAspectRatio(1, 1);
            }
        }
        if (!(intExtra == 0 || intExtra2 == 0)) {
            guidelines.setRequestedSize(intExtra, intExtra2).setAspectRatio(intExtra, intExtra2);
        }
        guidelines.setMaxZoom(50);
        guidelines.start(this);
    }

    /* access modifiers changed from: protected */
    @Override // android.support.v4.app.FragmentActivity
    public void onActivityResult(int i, int i2, Intent intent) {
        if (i == 203) {
            try {
                CropImage.ActivityResult activityResult = CropImage.getActivityResult(intent);
                if (i2 == -1) {
                    if (YYCutSDK.mOnYYCutListener != null) {
                        YYCutSDK.mOnYYCutListener.result(true, "裁剪成功", BitmapFactory.decodeStream(getContentResolver().openInputStream(activityResult.getUri())));
                    }
                } else if (i2 == 204 && YYCutSDK.mOnYYCutListener != null) {
                    YYCutSDK.OnYYCutListener onYYCutListener = YYCutSDK.mOnYYCutListener;
                    onYYCutListener.result(false, activityResult.getError().getMessage() + "", null);
                }
            } catch (Exception e) {
                e.printStackTrace();
            } catch (Throwable th) {
                finish();
                throw th;
            }
        }
        finish();
    }
}
